import { Assets } from "../consts/Assets";
import { EventNames } from "../consts/EventNames";
import { StateNames } from "../consts/StateNames";
import BaseState from "../core/BaseState";
import EventBus from "../core/EventBus";

export default class LoadAssertState extends BaseState {
    private readonly URL: string = "http://192.168.1.128:3400/img/";

    onEnter() {
        // toast("开始加载资源");

        for (let key in Assets.images) {
            let spec = Assets.images[key];
            spec.img = images.load(this.URL + key + '.png');
            if (spec.region.length <= 2) {
                spec.region.push(spec.img.getWidth(), spec.img.getHeight());
            }
        }

        setTimeout(() => {
            EventBus.emit(EventNames.LOAD_ASSETS_COMPLETE);
        }, 100);
    }

}